#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/**
 * 题目：有两个磁盘文件A和B,各存放一行字母，要求把这两个文件中的信息合并（按字母顺序排列），输出到一个新文件C中。
*/
int main(int argc, char const *argv[])
{
    FILE *fa, *fb, *fc;
    int i,j,k;
    char s1[100], s2[100];
    char tem;
    if((fa=fopen("a.i", "r")) == NULL)
    {
        printf("error: cannot open a.i file!\n");
        exit(0);
    }
    fgets(s1, 100, fa);
    s1[strcspn(s1, "\n")]='\0';
    fclose(fa);

    if((fb=fopen("b.i", "r")) == NULL)
    {
        printf("error: cannot open b.i file!\n");
        exit(0);
    }
    fgets(s2, 100, fb);
    s2[strcspn(s2, "\n")]='\0';
    fclose(fb);

    strcat(s1, s2);
    for(i=strlen(s1)-1; i>1; i--)
    {
        for(j=0; j<i; j++)
        {
            if(s1[j]>s1[j+1])
            {
                tem = s1[j];
                s1[j] = s1[j+1];
                s1[j+1] = tem;
            }
        }
    }
    if((fc=fopen("c.i", "w")) == NULL)
    {
        printf("error: cannot open c file!\n");
        exit(0);
    }
    fputs(s1, fc);
    fclose(fc);

    return 0;
}